const db = require('../db/index');
const DataType = require('sequelize');
const User = require('./User');
const Drives = require('./Drives');
/**es6继承 消费表*/
class Use extends DataType.Model {}
Use.init(
    {
        id: {
            type: DataType.INTEGER,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true
        },
        orderId: {
            type: DataType.STRING,
            comment: '订单号',
            defaultValue: 0,
            allowNull: false
        },
        userId: {
            type: DataType.INTEGER,
            comment: '用户ID',
            allowNull: false
        },
        merchantId: {
            type: DataType.INTEGER,
            comment: '所属商家ID',
            allowNull: false
        },
        deviceId: {
            type: DataType.STRING,
            comment: '设备ID',
            allowNull: false
        },
        address: {
            type: DataType.STRING,
            comment: '洗车地点',
            defaultValue: 0,
            allowNull: false
        },
        amount: {
            type: DataType.DECIMAL(10, 2),
            comment: '实际金额',
            defaultValue: 0,
            allowNull: false
        },
        payment: {
            type: DataType.STRING,
            comment: '支付方式',
            defaultValue: 0,
            allowNull: false
        },
        type: {
            type: DataType.BOOLEAN,
            comment: '0非奖励洗车 1奖励洗车',
            defaultValue: 0,
            allowNull: false
        },
        over: {
            type: DataType.BOOLEAN,
            comment: '0未 1已',
            defaultValue: 0,
            allowNull: false
        },
        status: {
            type: DataType.BOOLEAN,
            comment: '0删除 1正常',
            defaultValue: 0,
            allowNull: false
        }
    },
    {
        tableName: 'use',
        modelName: 'use',
        sequelize: db
    }
);
// Use.sync({ force: true });
Use.belongsTo(User['default'], { as: 'userData', foreignKey: 'userId' });
Use.belongsTo(Drives['default'], { as: 'drivesInfo', foreignKey: 'deviceId' });
exports['default'] = Use;
